<?php
import("ORG.Util.HashMap");
class BaseAction extends Action{

    var $mid;

    protected  function _initialize(){
        header("Content-Type:text/html; charset=UTF-8");

        $this->mid = Session::get("adminID");
        if(empty($this->mid)){
            $this->redirect("login","Public");
            exit;
        }

        $this->nav = D('Sysnav')->where("status<>0")->order('orderNum asc')->findAll();//导航菜单
        //dump($this->nav);
        $this->nav2 = D('Sysnav')->where("status=0")->order('orderNum asc')->findAll();//隐藏菜单
        $this->site = D('Syssite')->find('1');

        $this->lurl = Session::get('curl');
        $this->curl = $_SERVER['REQUEST_URI'];
        Session::set('curl',$this->curl);

		//权限判断开始
		$all_access = Session::get("access");

		$current_access= array(
            'action'=> 	strtolower(MODULE_NAME),
            'method'=> 	strtolower(ACTION_NAME),
			'nid'	=>	$_GET['nid'],
        );
        //dump($current_access);
        $hasNoPower = in_array($current_access, $all_access);
        if($hasNoPower){
            $this->error('您没有权限访问，请联系管理员！');
        }
		//权限判断结束
        
        //菜单tag
        if($_GET['menu']){Session::set("menu", $_GET['menu']);}
        $menutag = Session::get("menu");
        if(!$menutag) $menutag="content";
        $this->menutag = $menutag;

        //dump($this->menutag);

        parent::_initialize();
    }


    function _empty()
    {
        $this->error("请求的页面不存在");
    }

    function upload(){
        import("ORG.Net.UploadFile");
        $upload = new UploadFile();
        $upload->maxSize  = 32922000 ;
        $upload->allowExts  = explode(',','jpg,gif');
        $upload->savePath = './Public/file/';
        //执行上传操作
        $result = $upload->upload();
        if(!$result){
            $this->error("上传出错! ".$upload->getErrorMsg());
        }
        $result = $upload->getUploadFileInfo();
        for($i=0;$i<count($result);$i++){
            $upname[] = $result[$i]['savename'];
            $DaoAttach = D("Sysattach");
            $vo = $DaoAttach->create($result[$i]);
            if(false === $vo) {
                $this->error($DaoAttach->getError());
            }
            $rs = $DaoAttach->add();
        }
        return $upname;
    }
}

?>